#include <iostream>
using std::cout;
using std::endl;

//复数
class Complex
{
public:
    Complex(int real,int image)
    : _real(real)
    , _image(image)
    {}

    void print() const{
        cout << _real << " + " << _image << "i" << endl;
    }

    int getReal() const{ return _real; }
    int getImage() const{ return _image; }
private:
    int _real;
    int _image;
};

//采用普通函数进行重载
//通常不采用这种方式，因为get系列的公有函数让私有的成员
//几乎完全失去了隐藏的效果
Complex operator+(const Complex & lhs,const Complex & rhs){
    return Complex(lhs.getReal() + rhs.getReal(),
                   lhs.getImage() + rhs.getImage());
}

void test0(){
    int a = 1,b = 2;
    /* &(a + b); */
    cout << a + b << endl;

    Complex cx(1,2);
    Complex cx2(3,4);
    /* add(cx,cx2).print(); */


    //Complex cx3 = operator+(cx,cx2) //本质;
    Complex cx3 = cx + cx2;
    cx3.print();
}

void test1(){
    int num = 10;
    cout << sizeof(int) << endl;
    cout << sizeof(num)<< endl;
    cout << sizeof num << endl;
}

int main(void){
    test0();
    return 0;
}
